package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

import ${package.Service}.${table.serviceName};

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import lombok.RequiredArgsConstructor;

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@RequestMapping("<#if package.ModuleName??>/${package.ModuleName}</#if>")
@RequiredArgsConstructor
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    private final ${table.serviceName} service;

    /**
    * 查询实体列表
    *
    * @param page
    * @return
    */
    @GetMapping("/search")
    public JsonResult<${entity}VO> search(Page page) {
        return service.search(page);
    }

    /**
    * 新增实体
    *
    * @param view
    * @param bindingResult
    * @return
    */
    @PostMapping("/add")
    public JsonResult add(@Validated @RequestBody ${entity}VO view, BindingResult bindingResult) {
        return JsonResult.success(service.add(view));
    }

    /**
    * 逻辑删除实体
    *
    * @param id
    * @return
    */
    @PostMapping("/logicalDelete")
    public JsonResult logicalDelete(@RequestParam Long id) {
        service.logicalDelete(id);
        return JsonResult.SUCCESS();
    }

    /**
    * 更新实体
    *
    * @param view
    * @param bindingResult
    * @return
    */
    @PostMapping("/update")
    public JsonResult update(@Validated @RequestBody ${entity}VO view, BindingResult bindingResult) {
        return JsonResult.success(service.update(view));
    }

    /**
    * 获取实体
    *
    * @param id
    * @return
    */
    @GetMapping("/getById")
    public JsonResult getViewById(@RequestParam Long id) {
        return JsonResult.success(service.getViewById(id));
    }
}
</#if>
